package io.renren.modules.bs.controller;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;
import io.renren.modules.bs.entity.BsExtractRecordEntity;
import io.renren.modules.bs.service.BsExtractRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Map;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2019-08-15 23:03:14
 */
@RestController
@RequestMapping("bs/extractRecord")
public class BsExtractRecordController {
    @Autowired
    private BsExtractRecordService bsExtractRecordService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = bsExtractRecordService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{extractRecordId}")

    public R info(@PathVariable("extractRecordId") Long extractRecordId){
		BsExtractRecordEntity bsExtractRecord = bsExtractRecordService.getById(extractRecordId);

        return R.ok().put("bsExtractRecord", bsExtractRecord);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody BsExtractRecordEntity bsExtractRecord){
		bsExtractRecordService.save(bsExtractRecord);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody BsExtractRecordEntity bsExtractRecord){
		bsExtractRecordService.updateById(bsExtractRecord);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] extractRecordIds){

        try {
            bsExtractRecordService.removeRecords(Arrays.asList(extractRecordIds));
            return R.ok();
        } catch (Exception e) {
            e.printStackTrace();
            return R.error(e.getMessage());
        }
    }

    /**
     * 导出excel
     */
    @RequestMapping("/exportFile")

    public void exportFile(Long extractRecordId, HttpServletResponse response){
            bsExtractRecordService.exportFile(extractRecordId,response);
    }

}
